<?php

namespace App\Tools;

use App\Models\User;
use Illuminate\Support\Facades\Cache;

class Token1
{

    public static $token;

    public static $uid;

    public static $ttl = 9000;



    /**
     * 新用户设置Token
     * @param $uid
     * @return bool
     */
    public static function setUser($uid)
    {
        self::$token = 'token:'.unique_id();
        Cache::put(self::$token,$uid, self::$ttl);
        return self::$token;
    }

    public static function  getUserInfo($token){
       $uid = Cache::get($token);
       $data = User::find($uid);
       return $data;
    }

    /**
     * 刷新Token
     * @param $token
     * @return bool
     */
    public static function refresh($token)
    {
        self::$uid = Cache::get($token);
        if(!self::$uid)
            return false;
        Cache::put($token,self::$uid, self::$ttl);
        return true;
    }

    /**
     * 移除Token
     * @param $Token
     * @return bool
     */
    public static function forget($Token)
    {
        return Cache::forget($Token);
//        static::$token = null;
        return true;
    }


}
